Skip to content

[Improvement-17723][TaskPlugin] DmsTask resource leak repair#17718

Closed
niumy0701 wants to merge 26 commits intoapache:devfrom
niumy0701:DSIP-23-DmsTask
Closed

[Improvement-17723][TaskPlugin] DmsTask resource leak repair#17718
niumy0701 wants to merge 26 commits intoapache:devfrom
niumy0701:DSIP-23-DmsTask

Conversation

@niumy0701
Copy link

@niumy0701 niumy0701 commented Nov 25, 2025

Please refer to the details of main issue #14877
fix #17723

Purpose of the pull request

Brief change log

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(or)

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

Copy link
Member

@SbloodyS SbloodyS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #17719 (review)

@niumy0701 niumy0701 changed the title [DSIP-23][TaskPlugin] DmsTask resource leak repair [Improvement-17723][TaskPlugin] DmsTask resource leak repair Nov 25, 2025
@niumy0701 niumy0701 requested a review from SbloodyS November 25, 2025 07:59
@niumy0701 niumy0701 changed the title [Improvement-17723][TaskPlugin] DmsTask resource leak repair [Improvement-17723][TaskPlugin] DmsTask resource leak repair Nov 25, 2025
@niumy0701
Copy link
Author

Same as #17719 (review)

done
sub issue is #17723

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses resource leaks in the DMS task plugin by adding proper resource cleanup for AWS DMS clients and fixing a FileInputStream resource leak. However, the implementation introduces a critical bug in the checkFinishedReplicationTask() method where the client is shut down before it's fully used.

Key changes:

  • Added client.shutdown() calls to three methods (checkFinishedReplicationTask, stopReplicationTask, deleteReplicationTask) to prevent AWS client resource leaks
  • Fixed FileInputStream resource leak in replaceFileParameters using try-with-resources pattern
  • Added comprehensive test coverage for the replaceFileParameters method

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
DmsHook.java Added client shutdown calls to cleanup AWS DMS client resources; fixed FileInputStream leak with try-with-resources
DmsHookTest.java Added four new test cases for replaceFileParameters method covering null input, normal strings, existing files, and non-existent files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copy link
Member

@ruanwenjun ruanwenjun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add close method in DmsHook and close the hook in upper layer, if there throw any exception, still exist resource leak

@niumy0701 niumy0701 requested a review from ruanwenjun November 29, 2025 07:56
@niumy0701
Copy link
Author

You need to add close method in DmsHook and close the hook in upper layer, if there throw any exception, still exist resource leak

thanks , It has been modified and can be reviewed again

@niumy0701 niumy0701 requested a review from ruanwenjun December 5, 2025 03:06
ruanwenjun
ruanwenjun previously approved these changes Dec 8, 2025
Comment on lines +92 to +110
// if appIds is not empty, just track application status, avoid resubmitting remote task
if (StringUtils.isNotEmpty(taskRequest.getAppIds())) {
setAppIds(taskRequest.getAppIds());
trackApplicationStatus();
return;
}

// submit a remote application
submitApplication();

if (StringUtils.isNotEmpty(getAppIds())) {
taskRequest.setAppIds(getAppIds());
// callback to update remote application info
taskCallBack.updateRemoteApplicationInfo(taskRequest.getTaskInstanceId(),
new ApplicationInfo(getAppIds()));
}

// keep tracking application status
trackApplicationStatus();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWS DMS task types will not be submitted to yarn or k8s for execution, so this logic should not be added.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWS DMS task types will not be submitted to yarn or k8s for execution, so this logic should not be added.

DMSTask also executes the handle method. When rewriting the handle method, I added the logic to close resources

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two do not conflict or even have nothing to do with each other.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two do not conflict or even have nothing to do with each other.

Do you mean that DMS task does not involve resource leakage?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We've already safely close connection in cancelApplication

Copy link
Author

@niumy0701 niumy0701 Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We've already safely close connection in cancelApplication

Based on the previous discussion with @ruanwenjun , it is necessary to uniformly close resources in the handle method.
Shall we discuss and confirm again

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niumy0701 For such issues, please first provide evidence of resource leakage.

Copy link
Author

@niumy0701 niumy0701 Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niumy0701 For such issues, please first provide evidence of resource leakage.

okay,I am trying to simulate a resource leakage

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 8, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
9.5% Coverage on New Code (required ≥ 60%)

See analysis details on SonarQube Cloud

@ruanwenjun
Copy link
Member

Please provide relevant verification before and after the repair.

@ruanwenjun ruanwenjun closed this Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][TaskPlugin] DmsTask resource leak issue

4 participants